#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[10][10];
bool full_column[10][10];//表示0~9这个数字在i列已经被填入   [i][0~9]
bool full_row[10][10];
bool full_block[10][10];//表示0~9这个数字在k格已经被填入    [k][0~9]
ll hst_sco;
int form_score[10][10] = {
    {0,0,0,0,0,0,0,0,0,0},
    {0,6,6,6,6,6,6,6,6,6},
    {0,6,7,7,7,7,7,7,7,6},
    {0,6,7,8,8,8,8,8,7,6},
    {0,6,7,8,9,9,9,8,7,6},
    {0,6,7,8,9,10,9,8,7,6},
    {0,6,7,8,9,9,9,8,7,6},
    {0,6,7,8,8,8,8,8,7,6},
    {0,6,7,7,7,7,7,7,7,6},
    {0,6,6,6,6,6,6,6,6,6}
};

void update(ll cur_score) {
    cur_score = max(hst_sco,cur_score);
    return;
}

void dfs(int cur_row,int cur_column,int cur_score)
{
    if (a[cur_row][cur_column] != 0)
    {
        cur_score += form_score[cur_row][cur_column]*a[cur_row][cur_column];
        if (cur_row == 9 && cur_column == 9)
        {
            update(cur_score);
            return;
        }
        if (cur_column == 9)
            dfs(cur_row + 1, 1,cur_score);
        else 
            dfs(cur_row, cur_column + 1,cur_score);
    }
    if (a[cur_row][cur_column] == 0)
    {
        int k;
        if (cur_row <= 3)
            k = (cur_column + 2) / 3;
         else if (cur_row <= 6)
            k = (cur_column + 2) / 3 + 3;
         else
            k = (cur_column + 2) / 3 + 6;

        for (int x = 1; x < 10; ++x)
        {
            if (!full_column[cur_column][x] && !full_block[k][x] && !full_row[cur_row][x]) {
                cur_score += form_score[cur_row][cur_column]*x;
                full_row[cur_row][x] = true;
                full_column[cur_column][x] = true;
                full_block[k][x] = true;

                if (cur_column == 9 && cur_row == 9) {
                    update(cur_score);
                    return;
                }
                if (cur_column == 9) dfs(cur_row + 1, 1,cur_score);
                else dfs(cur_row, cur_column + 1,cur_score);

                cur_score -= form_score[cur_row][cur_column]*x;
                full_row[cur_row][x] = false;
                full_column[cur_column][x] = false;
                full_block[k][x] = false;
            }
        }
    }
}

int main()
{
    ios::sync_with_stdio(0);
    for (int row = 1; row < 10; ++row) {
        for (int column = 1; column < 10; ++column) {
            cin >> a[row][column];
            if (a[row][column] > 0) {
                int e = 0;
                if (row <= 3) {
                    e = (column + 2) / 3;
                } else if (row <= 6) {
                    e = (column + 2) / 3 + 3;
                } else {
                    e = (column + 2) / 3 + 6;
                }

                full_column[column][a[row][column]] = true;
                full_block[e][a[row][column]] = true;
                full_row[row][a[row][column]] = true;

            }
        }
    }
    dfs(1,1,0);
    cout << hst_sco;
    return 0;
}